import type { Request, ResponseToolkit } from "@hapi/hapi";
import Hapi from "@hapi/hapi";
import { Notes, User } from "../../model/index";

let route: Hapi.ServerRoute<Hapi.ReqRefDefaults> = {
  path: "/setCurrentNote",
  method: "get",
  handler: async (r: any, h: ResponseToolkit) => {
    try {
      console.log(r.query.id, " r.query.id");
      await Notes.updateMany({ pid: r.userId }, { status: false });
      await Notes.updateOne(
        { _id: r.query.id },
        {
          status: true,
        }
      );
      return { code: 200, data: true };
    } catch (err: any) {
      return err;
    }
  },
  options: {
    plugins: {
      "hapi-swagger": {
        security: [{ apiKey: [] }],
      },
    },
    tags: ["api"],
  },
};
export default route;
